﻿using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FTP_progress
{
    public partial class GitSet : Form
    {
        public GitSet()
        {
            InitializeComponent();
        }
        Sqlite sql = new Sqlite();
        private void btnSave_Click(object sender, EventArgs e)
        {
            Dictionary<string, Object> dict = new Dictionary<string, Object>();
            dict.Add("SourceFolder", txtSourceFolder.Text);
            dict.Add("GitlabUrl", txtGitlabUrl.Text);
            dict.Add("RepoPath", txtRepoPath.Text);
            dict.Add("UserName", txtUserName.Text);

            dict.Add("Pat", txtPat.Text);
            dict.Add("LogPath", txtLogPath.Text);
            dict.Add("LogFileName", txtLogFileName.Text);
            dict.Add("BranchName", txtBranchName.Text);

            string where = "ID=1";
            Dictionary<string, Object> whereParams = new Dictionary<string, object>();              
            whereParams.Add("ID", 1);

            try
            {
                sql.Update("git", dict, where, whereParams);
                
                MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }                   
        }

        private void GitSet_Load(object sender, EventArgs e)
        {
            DataTable dt = sql.Select("git", null, null);
            if (dt == null || dt.Rows.Count <= 0) return;

            txtSourceFolder.Text = dt.Rows[0][0].ToString().Trim();
            txtGitlabUrl.Text = dt.Rows[0][1].ToString().Trim();
            txtRepoPath.Text = dt.Rows[0][2].ToString().Trim();
            txtUserName.Text = dt.Rows[0][3].ToString().Trim();
            txtPat.Text = dt.Rows[0][4].ToString().Trim();
            txtLogPath.Text = dt.Rows[0][5].ToString().Trim();
            txtLogFileName.Text = dt.Rows[0][6].ToString().Trim();
            txtBranchName.Text = dt.Rows[0][7].ToString().Trim();

        }
    }
}
